<cfcomponent name="googleCheckOutReponseHandler" displayname="googleCheckOutReponseHandler" hint="Processes the Response from Google" extends="GoogleCheckout">
<!--- 
*******************************************************************************
 Copyright (C) 2006 Scott Pinkston
  
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
*******************************************************************************

Component: googleCheckOutReponseHandler
Created By: Scott Pinkston (spinkston@ozarka.edu)
Creation Date: 7/2/2006
Description:
Provides the response (notification API) and calls the reponse action
--->

	<cffunction name="processXmlData" output="false" returntype="string" hint="Parses the XML response from google" access="remote">
		<cfargument name="XMLData" required="true">
		<cfset var myDOM = "">
		<cfset var type= "">

        <cfif isBinary(XMLData)>
			<cfset myDOM = XmlParse(toString(XMLData))>
		<cfelse>
			<cfset myDOM = XmlParse(XMLData)>
		</cfif>
		
		<cfset type = structKeyList(myDOM)>	
			
		<CFSWITCH EXPRESSION="#type#">
			<CFCASE VALUE="new-order-notification">
				<!--- <new-order-notification> received --->
				<cfset ProcessNewOrderNotification(myDOM)>
			</CFCASE>
			
			<CFCASE VALUE="order-state-change-notification">
				<!--- <order-state-change-notification> received --->
				<cfset ProcessOrderStateChangeNotification(myDOM)>
			</CFCASE>

			<CFCASE VALUE="charge-amount-notification">
				<!--- <charge-amount-notification> received --->
				<cfset ProcessChargeAmountNotification(myDOM)>
			</CFCASE>

			<CFCASE VALUE="chargeback-amount-notification">
				<!--- <chargeback-amount-notification> received --->
				<cfset ProcessChargebackAmountNotification(myDOM)>
			</CFCASE>
		
			<CFCASE VALUE="refund-amount-notification">
				<!--- <refund-amount-notification> received --->
				<cfset ProcessRefundAmountNotification(myDOM)>
			</CFCASE>
			
			<CFCASE VALUE="risk-information-notification">
				<!--- <refund-amount-notification> received --->
				<cfset ProcessRefundAmountNotification(myDOM)>
			</CFCASE>
		</CFSWITCH>

		<cfset logNotification(myDOM)>
	
		<cfreturn myDOM>
	</cffunction>

	<cffunction name="SendNotificationAcknowledgement" output="false" returntype="string" hint="Returns the XML notification message for Google" access="Remote">
		<!---
		  The SendNotificationAcknowledgment function responds to a Google Checkout 
		  notification with a <notification-acknowledgment> message. If you do 
		  not send a <notification-acknowledgment> in response to a Google Checkout 
		  notification, Google Checkout will resend the notification multiple times.
		--->
	   <cfset var acknowledgment = "">

		<cfsavecontent variable="acknowledgment">
			<?xml version="1.0" encoding="UTF-8"?>
			<notification-acknowledgment xmlns="http://checkout.google.com/schema/2"/>
		</cfsavecontent>

		<cfreturn acknowledgment>
	</cffunction>

	<cffunction name="ProcessNewOrderNotification" output="false" returntype="String" description="">
		<cfargument name="XMLData" required="true" type="XML"> 
		<!--- Do new order notification processing --->
		<cfset var OrderNumber = #XMLData["new-order-notification"]["google-order-number"].xmltext#>
		<cfset var OrderAmount = #XMLData["new-order-notification"]["order-total"].xmltext#>

		<cflog text="#OrderNumber# New Order for #OrderAmount#" type="Information" file="GoogleCheckout" thread="yes" date="yes" time="yes" application="Yes"> 

<!---		
	Just playing here
		<cfoutput>
			<cfsavecontent variable="RtnMsg">
				<?xml version="1.0" encoding="UTF-8"?>
					<charge-order xmlns="http://checkout.google.com/schema/2" google-order-number="#orderNumber#">
					  <amount currency="USD">#OrderAmount#</amount>
				</charge-order>
			</cfsavecontent>			
		</cfoutput>	
		<cfhttp
		method="post"
		url="#variables.g_url##GetMerchantID()#/checkout">
		<cfhttpparam type="header" name="Authorization" value="Basic #GetHttpAUTH()#">
		<cfhttpparam type="header" name="Content-type" value="application/xml">
		<cfhttpparam type="header" name="Accept" value="application/xml">
		<cfhttpparam type="XML" value="#rtnMsg#">
		</cfhttp> 
--->	
	</cffunction>	

 	<cffunction name="ProcessOrderStateChangeNotification" output="false" returntype="String" description="">
		<cfargument name="XMLData" required="true" type="XML"> 
		<!--- Do order change status processing --->
		
	</cffunction>	

	<cffunction name="ProcessChargeAmountNotification" output="false" returntype="String" description="">
		<cfargument name="XMLData" required="true" type="XML"> 
		<!--- Do Charged amount processing, the money was actually charged to the person --->
		
	</cffunction>	

	<cffunction name="ProcessChargebackAmountNotification" output="false" returntype="String" description="">
		<cfargument name="XMLData" required="true" type="XML"> 
		<!--- Do chargeBack processing --->
		
	</cffunction>	

	<cffunction name="ProcessRefundAmountNotification" output="false" returntype="String" description="">
		<cfargument name="XMLData" required="true" type="XML"> 
		<!--- Do Refund amount notification processing --->
		
	</cffunction>	

	<cffunction name="ProcessRiskInformationNotification" output="false" returntype="String" description="">
		<cfargument name="XMLData" required="true" type="XML"> 
		<!--- Do risk notification processing --->
		
	</cffunction>	

	<cffunction name="LogNotification" output="false" returntype="void">
		<cfargument name="XMLData" required="true" type="XML"> 
		
		<!--- Log the Response --->
		<!---
		Uncomment this to create a local XML file of what google sends to the response handler
		<cffile action="write" output="#Arguments.XMLData#" file="c:\temp\GoogleCheckout\#createUUID()#.xml">
		--->
		
	</cffunction>

	
</cfcomponent>